package cat.joronya.supermanager.service;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Messenger;

/**
 * Extenem el inten per sobreescriure el equals i poder 
 * comprovar si ja esta encuat l'Intent al Service.
 * Son Intents preparats per executar el SupermanagerService.
 * 
 * @author pol
 *
 */
public class SupermanagerIntent extends Intent 
{
	public static final String ACTION_LOGIN = "login";
	
	public SupermanagerIntent(String action, Context packageContext, Handler handler)
	{
		super(action, null, packageContext, SupermanagerService.class);
		if( handler == null)
			putExtra("cat.joronya.supermanager.messenger", (Messenger)null);
		else
			putExtra("cat.joronya.supermanager.messenger", new Messenger(handler));
	}
	
	public SupermanagerIntent(String action, Uri uri, Context packageContext, Handler handler)
	{
		super(action, uri, packageContext, SupermanagerService.class);
		if( handler == null )
			putExtra("cat.joronya.supermanager.messenger", (Messenger)null);
		else
			putExtra("cat.joronya.supermanager.messenger", new Messenger(handler));
	}
	
	/**
	 * Considerem dos intents iguals si:
	 * -s'executen sobre el mateix tipus
	 * -s'executa la mateixa accio
	 */
	@Override
	public boolean equals(Object o) 
	{
		Intent intent = (Intent)o;
		return  intent.getData() == this.getData() 
			&& intent.getAction() == this.getAction();
	}
	
}
